class Solution:
    def sortSentence(self, s: str) -> str:
        words = s.split()
        words.sort(key=lambda x: int(x[-1]))
        return " ".join(word[:-1] for word in words)


if __name__ == "__main__":
    print(Solution().sortSentence("is2 sentence4 This1 a3"))  # "This is a sentence"
    print(Solution().sortSentence("Myself2 Me1 I4 and3"))  # "Me Myself and I"
